@echo off
chcp 65001 >nul
powershell -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8"

echo ========= 清理旧文件 =========
del /f /q putty.exe 2>nul
del /f /q putty.tmp.exe 2>nul

echo ========= 编译 Go 源码为 putty.tmp.exe =========
go build -o putty.tmp.exe putty.go

if not exist putty.tmp.exe (
    echo ❌ 编译失败！
    pause
    exit /b 1
)

echo ========= 使用 UPX 压缩为 putty.exe =========
upx --best --lzma -o putty.exe putty.tmp.exe

if exist putty.exe (
    echo ✅ 编译并压缩成功！生成文件：putty.exe
    del /f /q putty.tmp.exe
) else (
    echo ❌ upx 压缩失败！
    pause
    exit /b 1
)

echo ✅ 构建完成，最终文件：putty.exe
pause
